#pragma once
#include <fcgi_stdio.h>
#include <string.h>
#include <libjson.h>
#include "JsonRequest.hpp"
#include "sql_string.h"
#include <mysql/mysql.h>

#define BEGIN_REQUEST_HANDLER() \
	bool request_handler(const char* handler) \
	{ \

#define END_REQUEST_HANDLER() \
		return false; \
	}\

#define REQUEST(name, cls) \
	if( 0 == strcasecmp(handler, name) ) \
	{ \
		cls c; \
		c.handler(); \
		return true; \
	} \


using namespace libjson;

namespace http
{
	bool	getValue(const char* str, const char* key, std::string& value);
	void	decodeUri(const char* start, const char* end, std::string& ret);
}

namespace request
{
	void	reset();
	bool	get(const char* name, std::string& value);
	bool	post(const char* name, std::string& value);
	bool	file(const char* name, std::string& value);
}

namespace sys
{
	char*	readFile(const char* file);
	void	parseConfig(char* buffer, void (*callback)(const char*, const char*));
}

namespace sql
{
	long	execute(const char* sql);
	bool	query(const char* sql, bool (*callback)(void* context, int r, int c, MYSQL_ROW row), void* context);
	bool	signalQuery(const char* sql, ...);
}


